package com.bff.gaia.client.combine;

import com.bff.gaia.api.common.Plan;
import com.bff.gaia.client.combine.planutil.GetConfigure;
import com.bff.gaia.client.combine.planutil.PlanComputeUtil;
import com.bff.gaia.client.combine.planutil.PlanDataFlowInformation;

import java.util.List;

public class PlanAndInfo {

	private Plan plan;
	private long fizeSize;
	private long ramSize;
	private int operatorSumNumber;
	private boolean type = false;

	//按文件大小划分作业合并类型
	private boolean mergeType = false;

	//以Source 节点为基础每个链的平均长度 总算子数/source个数
	private int avLength = 0;
	private int[][] operatorNumber;
	private int dataFlowDept = 0;

	private int maxParallizer = 0; // DataFlow所有算子中并行度最大的值

	// Plan defaultParallelism 并行度
	private int pParallizer = 0;

	private int workComplex = 0;// DataFlow 复杂度

	private List<String> sourcePath;
	private List<String> sinkPath;


	public PlanAndInfo(Plan plan) {
		this.plan = plan;
		PlanDataFlowInformation pdf = new PlanDataFlowInformation(plan);

		//此处要能获得Slot大小的值
		float slotSize = GetConfigure.getSlotSize();
		this.ramSize = PlanComputeUtil.getRAMSize(plan.getMaximumParallelism(),slotSize);  //默认Slot大小是1G

		//流程图的部分属性信息
		this.workComplex = pdf.getWorkComplex();
		this.dataFlowDept = pdf.getDept();
		this.operatorSumNumber = pdf.getOperatorSumNumber();
		this.maxParallizer = pdf.getMaxParallizer();
		this.pParallizer = plan.getDefaultParallelism();
		this.avLength = pdf.getAvLength();
		this.operatorNumber = pdf.getOperatorNumbersAndParallizer();
		this.type = pdf.getType();
		System.out.println("所有Sinks节点都已经获取完毕！！！！");

		if(this.fizeSize>this.ramSize){
			this.type = false;
		}
		//获取输入 输出 文件路径
		this.sinkPath = pdf.getSinkFiles();
		System.out.println("Sinks文件的路径为："+this.sinkPath.get(0).toString());
		this.sourcePath = pdf.getSourceFiles();
		System.out.println("Sinks文件的路径为："+this.sourcePath.get(0).toString());
		//获取文件大小和分配的内存资源的大小
		this.fizeSize = PlanComputeUtil.getWorkFileSize(this.sourcePath);

		if(this.fizeSize < this.ramSize/2){
			this.mergeType = true;
		}
		else{
			System.out.println("MergeType字段是false");
		}
	}

	public Plan getPlan() {
		return plan;
	}

	public long getFizeSize() {
		return fizeSize;
	}

	public long getRamSize() {
		return ramSize;
	}

	public boolean isMergeType() {
		return mergeType;
	}

	public int getOperatorSumNumber() {
		return operatorSumNumber;
	}

	public boolean isType() {
		return type;
	}

	public int getAvLength() {
		return avLength;
	}

	public int[][] getOperatorNumber() {
		return operatorNumber;
	}

	public int getDataFlowDept() {
		return dataFlowDept;
	}

	public int getMaxParallizer() {
		return maxParallizer;
	}

	public int getpParallizer() {
		return pParallizer;
	}

	public int getWorkComplex() {
		return workComplex;
	}

	public List<String> getSourcePath() {
		return sourcePath;
	}

	public List<String> getSinkPath() {
		return sinkPath;
	}

	@Override
	public String toString() {
		return "PlanAndInfo{" +
			"plan=" + plan +
			", fizeSize=" + fizeSize +
			", ramSize=" + ramSize +
			", operatorSumNumber=" + operatorSumNumber +
			", type=" + type +
			", avLength=" + avLength +
			", dataFlowDept=" + dataFlowDept +
			", maxParallizer=" + maxParallizer +
			", pParallizer=" + pParallizer +
			", workComplex=" + workComplex +
			'}';
	}
}